


#!/bin/bash
#Author:    zhangyu
#Date:    	2016/09/08

##################################################
#define vars & functions

MYDBPWD='xxx'
SLAVE_DELAY=60
DBNAME='db1'
MONITOR_DBNAME='percona'

##################################################
#params check

if [ $# -ne 1 ]
then 
    echo "Just input one argument." 
fi

case $1 in
    delay_check)
        result=$(
				mysql -uroot -p${MYDBPWD} ${DBNAME} -s 2>/dev/null <<EOF
					select 
					    timestampdiff(second,
					        loc.hb_time,
					        src.hb_time) > ${SLAVE_DELAY} flag
					from
					    sync_hbt loc,
					    master_sync_hbt src;
EOF
)
            echo $result 
            ;;
        consistency_check)
        result=$(
				mysql -uroot -p${MYDBPWD} -s ${MONITOR_DBNAME} 2>/dev/null <<EOF
					select 
					    max(diff) > 0 flag
					from
					    monitor_data_sync
					where
					    check_time between curdate() and now();
EOF
)
            echo $result 
            ;;

        *) 
        echo "Usage:$0(delay_check|consistency_check)"
        ;;
esac